package com.yuejian.neusoft.yuejian_24.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yuejian.neusoft.yuejian_24.R;
import com.yuejian.neusoft.yuejian_24.javaBean.Class;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by q4549 on 2017/10/15.
 */

public class ClassListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public ClassListAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.class_cardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Class entity = (Class) mDataList.get(position);
        if (null == entity){
            return;
        }else {
            final ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.class_name.setText(entity.getClass_name());
            boolean setUp = viewHolder.player_list_video.setUp("http://10.0.2.2/yuejian/Public/video/"+entity.getClass_video(), JCVideoPlayer.SCREEN_LAYOUT_LIST, "");
            if (setUp) {
                Glide.with(mContext).load("http://10.0.2.2/yuejian/Public/photo/"+entity.getClass_pic()).into(viewHolder.player_list_video.thumbImageView);
            }
//            Picasso.with(mContext).load("ehttp://10.0.2.2/yuejian/Public/photo/"+entity.getClass_pic()).into(viewHolder.class_img);
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView class_name;
        LinearLayout class_container;
        JCVideoPlayerStandard player_list_video;

        public ViewHolder(View itemView) {
            super(itemView);
            class_name = (TextView) itemView.findViewById(R.id.class_name);
            class_container= (LinearLayout)itemView.findViewById(R.id.class_container);
            player_list_video = (JCVideoPlayerStandard)itemView.findViewById(R.id.player_list_video);
        }
    }
}

